import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/views/Home'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    children: [
      {
        path: '/user',
        name: 'User',
        component: () => import('@/components/home/User'),
        meta:
        {
          title: '用户页面'
        }
      },
      {
        path: '/goods',
        name: 'Goods',
        component: () => import('@/components/home/Goods'),
        meta:
        {
          title: '商品页面'
        }
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/Login')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to, from, next) => {
  console.log(to)
  document.title = to.meta.title;
  next()
})
export default router
